import { Message } from 'element-ui';
import validate from '@/utils/validate';

const { isEmpty } = validate;

export default function check (checkObj) {
  let checkRes = true;
  const validKeys = [
    { key: 'type', name: '审批类型' },
    { key: 'status', name: '审批状态' },
    { key: 'endorserTypeLevel1', name: '一级审批' },
  ];

  for (const valid of validKeys) {
    const checkMid = isEmpty(checkObj[valid.key]);
    if (checkMid) {
      Message.error(`${valid.name}不能为空`);
      checkRes = false;
      break;
    }
  }

  // const approves = [
  //   { key: 'endorserTypeLevel1', name: 'endorserLevel1' }
  // ];
  const approves = ['一', '二', '三', '四', '五'];
  for (let i = 1; i < 6; i++) {
    if ((checkObj[`endorserTypeLevel${i}`] === 0) && isEmpty(checkObj[`endorserLevel${i}`])) {
      Message.error(`${approves[i - 1]}级审批，指定员工不能为空`);
      checkRes = false;
      break;
    }
  }

  return checkRes;
}
